package cn.lizemin.demo.annotation;

import cn.lizemin.demo.parent.People;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @author: lizemin
 * @version: 1.0
 */
public class Demo {
    //这是一个main方法,是程序的入口
    public static void main(String[] args) throws NoSuchFieldException, NoSuchMethodException {

        //获取类上的注解,该类的反射对象
        Class<Person> personClass = Person.class;

        //通过下面的方法创建MyAnnotation的实例对象
        MyAnnotation annotation = personClass.getAnnotation(MyAnnotation.class);
        System.out.println(annotation.getValue());

        //获取成员变量上的注解
        Field age = personClass.getDeclaredField("age");
        MyAnnotation annotation_on_field = age.getAnnotation(MyAnnotation.class);
        System.out.println(annotation_on_field.getValue());

        //获取say方法上的注解
        Method say = personClass.getMethod("say");
        MyAnnotation annotation_on_method = say.getAnnotation(MyAnnotation.class);
        System.out.println(annotation_on_method.getValue());

        //获取defaultMethod方法上的注解
        Method defaultMethod = personClass.getMethod("defaultMethod");
        MyAnnotation annotation_on_defaultMethod = defaultMethod.getAnnotation(MyAnnotation.class);
        System.out.println(annotation_on_defaultMethod.getValue());


    }

}
